package Ms

import (
	"errors"
	"fmt"
	"db2s/global"
	"db2s/parDef"
)
func (dml DmlF) writeFileDML(parameter parDef.Parameter) (result global.Return, err error) {
	if parameter.ExecDML.FilePoint == nil {
		return
	}
	if err = parameter.ExecDML.FilePoint.Write("", parameter.ExecDML.Sql); err != nil {
		return
	}
	return
}

func (dml DmlF) connExecDML(parameter parDef.Parameter) (result global.Return, err error) {
	var event = "[ExecDDL]"
	if result.TimeOut, result.Result, err = newExecUpdateSql(ExecSqlInputS{
		Ss:           parameter,
		Event:        event,
		UpdateSqlStr: []string{parameter.ExecDML.Sql},
	}); err != nil {
		return
	}
	return
}

func (dml DmlF) ExecDML(parameter parDef.Parameter) (result global.Return, err error) {
	switch parameter.Options.RepairMethod {
	case "table":
		return dml.writeFileDML(parameter)
	case "file":
		return dml.connExecDML(parameter)
	default:
		err = errors.New(fmt.Sprintf("The repair method was not matched"))
	}
	return
}